<div class="login_div">
    <form action='<?php echo buildUrl('/user/barber/sublogin');?>' method="post" id='login_form'>
        <?php if($_GET["msg"]==1){?>
        <div><font style="color:red">账号或验证码错误</font></div>
        <?php }?>
        <div class='form-group'>
            <input type="text" class="form-control" id='account' name='account' placeholder="手机号" value=""/>
        </div>
        <div class='form-group' style="text-align: right">
            <input type="text" class="form-control" name="code" placeholder="验证码" value=""/><br/>
            <button type="button" id='subcode' onclick="_code();" style='width:10rem'>获取验证码</button>
        </div>
        <div class="form-group login_sub">
            <input type="submit" class="btn btn-info" name="登录" value="登录">
        </div>
    </form>
</div>
<script type='text/javascript'>
    $("#login_form").validate({
        rules: {
            account: {
                required: true,
                number: true,
                mobile: true

            },
            code: {
                required: true,
                rangelength: [6, 6]
            }
        },
        messages: {
            account: {
                required: '请输入手机号',
                number: '请输入手机号',
                mobile: '请输入手机号'
            },
            code: {
                required: '请输入验证码',
                rangelength: '请输入验证码'
            }
        }
    });
    jQuery.validator.addMethod("mobile", function (value, element) {
        var length = value.length;
        var mobile = /^(((1[1-9]{1}[0-9]{1})|(15[0-9]{1}))+\d{8})$/
        return this.optional(element) || (length == 11 && mobile.test(value));
    }, "手机号码格式错误");

    function _code() {
        var mobile = $("#account").val();
        $.ajax({url: "/user/barber/code?mobile=" + mobile, async: true, success: function (msg) {
                if (msg != 'true') {
                    alert(msg);
                    return false;
                }
                $("#subcode").text('60');
                $("#subcode").attr('disabled', 'disabled');
                var t = setInterval(function () {
                    var m = $("#subcode").text();
                    var str = parseInt(m) - 1;
                    if (str <= 0) {
                        str = '获取验证码';
                        $("#subcode").removeAttr('disabled');
                        clearInterval(t);
                    }
                    $("#subcode").text(str);
                }, 1000);
            }
        });
    }
</script>